package cn.cqvie.controller;

import cn.cqvie.common.R;
import cn.cqvie.pojo.ShoppingCart;
import cn.cqvie.service.ShoppingCartService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/shoppingCart")
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;

    @GetMapping("/getMSG")
    public R<Page> getPage(int page,int pageSize,String name){
        Page<ShoppingCart> myPage=new Page<>(page,pageSize);
        LambdaQueryWrapper<ShoppingCart> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.orderByDesc(ShoppingCart::getCreateTime);
        queryWrapper.like(StringUtils.isNotEmpty(name),ShoppingCart::getName,name);
        shoppingCartService.page(myPage,queryWrapper);
        return R.success(myPage);
    }
}
